#!/usr/bin/python3
# -*- coding:utf-8 -*-
# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
# This file is a part of the CANN Open Software.
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# ======================================================================================================================

import os
import torch
import numpy as np


def edge32_hor_c3_sum(img, width, height):
    output = np.zeros_like(img)
    nr = 16
    x_start = 16
    x_end = width - 9
    for c in range(3):
        channel = img[:, :, c]
        kernel = np.ones(nr) / nr
        conv = np.apply_along_axis(
            lambda x: np.convolve(x, kernel, mode='valid'), 
            axis=1, 
            arr=channel
        )
        output_start = x_start - (nr // 2 - 1)
        output_end = output_start + (x_end - x_start)
        output[:, x_start:x_end, c] = conv[:, output_start:output_end]
    return output


def gen_golden_data_simple():

    dtype = np.uint8
    width, height = 4887, 3440

    dtype = np.uint8
    input_shape = [height, width, 3]
    output_shape = [height, width, 3]

    img = np.random.uniform(0, 255, input_shape).astype(dtype)
    img_zero = np.zeros(output_shape, dtype=np.uint8)
    golden = edge32_hor_c3_sum(img, width, height)

    os.system("mkdir -p input")
    os.system("mkdir -p output")
    img.astype(dtype).tofile("./input/input_img.bin")
    img_zero.astype(dtype).tofile("./input/img_zero.bin")
    golden.tofile("./output/golden.bin")

if __name__ == "__main__":
    gen_golden_data_simple()

